
<?php

header("content-type:text/html;charset=utf-8");

testAction();

/**
 * 模拟post进行url请求
 * @param string $url
 * @param string $param
 */
function request_post($url = '', $param = '')
{
    if (empty($url) || empty($param)) {
        return false;
    }

    $postUrl = $url;
    $curlPost = $param;
    $ch = curl_init(); //初始化curl
    curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
    $data = curl_exec($ch); //运行curl
    curl_close($ch);

    return $data;
}

function testAction()
{
    $url = 'http://localhost:8080/sendMessage/sms';
    $post_data['mobiles'] = '15306325242';
    $post_data['tempId'] = '5aac268822f74ed1add7351bd22bf7d8';
    $post_data['params'] = '147258,20180815123456,万人授权店,山东省枣庄市滕州市,问天广场C座,创造者,13563201308,服务申请';

    $o = "";
    foreach ($post_data as $k => $v) {
        $o .= "$k=" . urlencode($v) . "&";
    }
    $post_data = substr($o, 0, -1);

    $res = request_post($url, $post_data);
    print_r($res);

}

